<?php
/**
 * 补报审核模型
 * @author jianhui
 *
 */
class supplementAuditModel extends MY_Model{
    var $fundTypeConf;
    var $validAuditTimeUnitList = NULL;
    function supplementAuditModel(){
        parent::MY_Model();
        $this->table = 'supplementAudit';
        $this->fundTypeConf = array(1=>'专营店活动', 2=>'城市联合');
    }
    /**
     * 包装数据
     * @param array $list
     * @return Ambigous <string, unknown>
     */
    function packing($list = array()){
        //时间单位配置
        $this->CI->load->model('timeUnitModel');
        $timeUnitList = $this->CI->timeUnitModel->getCacheData('timeUnitList');
        foreach ($list as $k => $v){
            //基金类型
            $list[$k]['fundTypeStr'] = isset($this->fundTypeConf[$v['fundType']]) ? $this->fundTypeConf[$v['fundType']] : '';
            //时间单位
            $list[$k]['timeUnitStr'] = isset($timeUnitList[$v['year']][$v['timeUnit']]) ? $timeUnitList[$v['year']][$v['timeUnit']] : '';
            //开始结束时间
            $list[$k]['startTimeStr'] = date("Y-m-d H:i:s", $v['startTime']);
            $list[$k]['endTimeStr'] = date("Y-m-d H:i:s", $v['endTime']);
        }
        return $list;
    }
    /**
     * 获取有效审核时段列表，并以年份分组
     */
    function getValidAuditTimeUnitList($fundType){
        if (is_null($this->validAuditTimeUnitList)){
            $nowTime = time();
            $list = $this->getList(array('fundType'=>$fundType,'startTime <'=>$nowTime,'endTime >'=>$nowTime,'isDel'=>0));
            $validAuditTimeUnitList = array();
            foreach ($list as $v){
                isset($validAuditTimeUnitList[(int)$v['year']]) || $validAuditTimeUnitList[(int)$v['year']] = array();
                $validAuditTimeUnitList[(int)$v['year']][] = (int)$v['timeUnit'];
            }
            $this->validAuditTimeUnitList = $validAuditTimeUnitList;
        }
        return $this->validAuditTimeUnitList;
    }
}